/**
 * 项目名：五位一体化工安全信息平台
 * 日期：    2019-12-08 15:07:43
 * Copyright (c) 2015- joysuch-版权所有
 */
package com.joysuch.wwyt.bp.controller;

import com.joysuch.wwyt.bp.bean.contractor.BpCertExpireRemindBean;
import com.joysuch.wwyt.bp.bean.contractor.BpContractorBean;
import com.joysuch.wwyt.bp.bean.contractor.BpContractorCertBean;
import com.joysuch.wwyt.bp.bean.contractor.BpContractorNameDto;
import com.joysuch.wwyt.bp.entity.contractor.BpContractor;
import com.joysuch.wwyt.bp.service.BpContractorService;
import com.joysuch.wwyt.core.bean.SimpleInfoBean;
import com.joysuch.wwyt.core.common.ajax.ResultBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 承包商管理
 */
@RestController
@RequestMapping("/bp/contractor")
@Api(tags = "承包商管理")
public class BpContractorController {

    @Autowired
    private BpContractorService bpContractorService;

    @PostMapping("save")
    @ApiOperation(value = "承包商-新增/修改", response = BpContractorBean.class)
    @RequiresPermissions("bp:contractor:save")
    public ResultBean save(@Valid @RequestBody BpContractorBean bean) {
        return bpContractorService.save(bean);
    }

    @GetMapping("page")
    @ApiOperation(value = "承包商-分页查询", response = BpContractor.class)
    public ResultBean page(Pageable page, String contractorType,Boolean locateSync, String companyName) {
        return bpContractorService.page(page, contractorType,locateSync, companyName);
    }

    @GetMapping("simple-page")
    @ApiOperation(value = "承包商列表-分页查询", response = BpContractor.class)
    public ResultBean simplePage(Pageable page, String nameOrCode) {
        Page<SimpleInfoBean> contractorPage = bpContractorService.simplePage(page, nameOrCode);
        return ResultBean.pageData(contractorPage.getContent(), contractorPage.getTotalElements());
    }

    @GetMapping("allContractor")
    @ApiOperation(value = "查询所有承包商", response = BpContractorNameDto.class)
    public ResultBean allContractor() {
        return bpContractorService.allContractor();
    }

    @GetMapping("nullify")
    @ApiOperation("承包商-作废")
    @RequiresPermissions("bp:contractor:nullify")
    public ResultBean nullify(Long id) {
        return bpContractorService.nullify(id);
    }

    @PostMapping("batchNullify")
    @ApiOperation("承包商-批量作废")
    @RequiresPermissions("bp:contractor:batchNullify")
    public ResultBean batchNullify(@RequestBody List<Long> ids) {
        return bpContractorService.batchNullify(ids);
    }


    @GetMapping("get")
    @ApiOperation(value = "承包商-单体查询", response = BpContractorBean.class)
    public ResultBean getById(Long id) {
        return bpContractorService.getById(id);
    }

    @PostMapping("contractor-cert-save")
    @ApiOperation(value = "承包商资质证书-新增/修改", response = BpContractorCertBean.class)
    @RequiresPermissions("bp:contractor:contractor-cert-save")
    public ResultBean contractorCertSave(@Valid @RequestBody BpContractorCertBean bean) {
        return bpContractorService.contractorCertSave(bean);
    }

    @GetMapping("contractor-cert-nullify")
    @ApiOperation("承包商资质证书-作废")
    @RequiresPermissions("bp:contractor:contractor-cert-nullify")
    public ResultBean contractorCertNullify(Long id) {
        return bpContractorService.contractorCertNullify(id);
    }

    @PostMapping("contractor-cert-remind-save")
    @ApiOperation("承包商资质证书过期提醒-新增/修改")
    @RequiresPermissions("bp:contractor:contractor-cert-remind-save")
    public ResultBean certRemindSave(@RequestBody BpCertExpireRemindBean bean) {
        return bpContractorService.certRemindSave(bean);
    }

    @GetMapping("contractor-cert-remind-get")
    @ApiOperation("承包商资质证书过期提醒-查询")
    public ResultBean certRemindGet() {
        return bpContractorService.certRemindGet();
    }

    @GetMapping("company-list")
    @ApiOperation("查询所有公司-包含承包商")
    public ResultBean companyList() {
        return bpContractorService.companyList();
    }

}
